package edu.govschool2010.screens;

import android.R.color;
import android.app.Activity;
import android.graphics.Color;
import android.opengl.Visibility;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

public class ActionsScreen extends Activity {
    /** Called when the activity is first created. */
	
	int vCount, bCount, awCount, wCount, btCount, gCount, aCount;
	//LinearLayout wl = null; 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        /*
        final LinearLayout container = new LinearLayout(this);
        container.setOrientation(LinearLayout.VERTICAL);
        
        
        //Setup linear layout for buttons
        LinearLayout buttons = new LinearLayout(this);
        ImageButton volumeButton = new ImageButton(this);
        int i = R.drawable.test;
        volumeButton.setImageResource(i);
        ImageButton brightnessButton = new ImageButton(this);
        brightnessButton.setImageResource(i);
        ImageButton awayButton = new ImageButton(this);
        awayButton.setImageResource(i);
        final ImageButton wifiButton = new ImageButton(this);
        wifiButton.setImageResource(i);
        ImageButton bluetoothButton = new ImageButton(this);
        bluetoothButton.setImageResource(i);
        ImageButton gpsButton = new ImageButton(this);
        gpsButton.setImageResource(i);
        ImageButton airplaneButton = new ImageButton(this);
        airplaneButton.setImageResource(i);
        buttons.addView(volumeButton);
        buttons.addView(brightnessButton);
        buttons.addView(awayButton);
        buttons.addView(wifiButton);
        buttons.addView(bluetoothButton);
        buttons.addView(gpsButton);
        buttons.addView(airplaneButton);
        container.addView(buttons);
        setContentView(container);*/
        
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        final int displayWidth = metrics.widthPixels;
        int displayHeight = metrics.heightPixels;
        
        //event for wifi button
        //final LinearLayout container = (LinearLayout) findViewById(R.id.Container);
        final LinearLayout actions = (LinearLayout) findViewById(R.id.Actions);
        //actions.setOrientation(LinearLayout.VERTICAL);
        //actions.setBackgroundColor(Color.BLACK);
        //actions.setHeight()
        
        ImageButton wButton = (ImageButton) findViewById(R.id.WifiButton);
        wCount=-1;
        //final LinearLayout wl = new LinearLayout(this);
        wButton.setOnClickListener(new View.OnClickListener() {
        	LinearLayout wl = new LinearLayout(ActionsScreen.this);
			public void onClick(View v) {
				if(wCount==-1) {
				//if button is selected then deselect and set wifiisused to false
				//if button is not selected then select and set wifiisused to true
				//ll.setMargins(0,0,0,1);
				TextView tv = new TextView(ActionsScreen.this);
				tv.setText("Wi-Fi");
				tv.setTextSize(20);
				tv.setWidth((int)(displayWidth*.80));
				CheckBox cb = new CheckBox(ActionsScreen.this);
				wl.addView(tv);
				wl.addView(cb);
				actions.addView(wl);
				wCount += 2;
				}
				else if (wCount == 0) {
					actions.addView(wl);
					wCount++;
				}
				else {
					actions.removeView(wl);
					wCount--;
				}
			}
		});
        
        ImageButton btButton = (ImageButton) findViewById(R.id.BluetoothButton);
        btCount=-1;
        //final LinearLayout btl = new LinearLayout(this);
        btButton.setOnClickListener(new View.OnClickListener() {
        	LinearLayout btl = new LinearLayout(ActionsScreen.this);
			public void onClick(View v) {
				if(btCount==-1) {
				//if button is selected then deselect and set wifiisused to false
				//if button is not selected then select and set wifiisused to true
				//ll.setMargins(0,0,0,1);
				TextView tv = new TextView(ActionsScreen.this);
				tv.setText("Bluetooth");
				tv.setTextSize(20);
				tv.setWidth((int)(displayWidth*.80));
				CheckBox cb = new CheckBox(ActionsScreen.this);
				btl.addView(tv);
				btl.addView(cb);
				actions.addView(btl);
				btCount += 2;
				}
				else if (btCount == 0) {
					actions.addView(btl);
					btCount++;
				}
				else {
					actions.removeView(btl);
					btCount--;
				}
			}
		});
        
        ImageButton gButton = (ImageButton) findViewById(R.id.GpsButton);
        gCount=-1;
        //final LinearLayout gl = new LinearLayout(this);
        gButton.setOnClickListener(new View.OnClickListener() {
        	LinearLayout gl = new LinearLayout(ActionsScreen.this);
			public void onClick(View v) {
				if(gCount==-1) {
				//if button is selected then deselect and set wifiisused to false
				//if button is not selected then select and set wifiisused to true
				//ll.setMargins(0,0,0,1);
				TextView tv = new TextView(ActionsScreen.this);
				tv.setText("GPS");
				tv.setTextSize(20);
				tv.setWidth((int)(displayWidth*.80));
				CheckBox cb = new CheckBox(ActionsScreen.this);
				gl.addView(tv);
				gl.addView(cb);
				actions.addView(gl);
				gCount += 2;
				}
				else if (gCount == 0) {
					actions.addView(gl);
					gCount++;
				}
				else {
					actions.removeView(gl);
					gCount--;
				}
			}
		});
        
        ImageButton aButton = (ImageButton) findViewById(R.id.AirplaneButton);
        aCount=-1;
        //final LinearLayout gl = new LinearLayout(this);
        aButton.setOnClickListener(new View.OnClickListener() {
        	LinearLayout al = new LinearLayout(ActionsScreen.this);
			public void onClick(View v) {
				if(aCount==-1) {
				//if button is selected then deselect and set wifiisused to false
				//if button is not selected then select and set wifiisused to true
				//ll.setMargins(0,0,0,1);
				TextView tv = new TextView(ActionsScreen.this);
				tv.setText("Airplane Mode");
				tv.setTextSize(20);
				tv.setWidth((int)(displayWidth*.80));
				CheckBox cb = new CheckBox(ActionsScreen.this);
				al.addView(tv);
				al.addView(cb);
				actions.addView(al);
				aCount += 2;
				}
				else if (aCount == 0) {
					actions.addView(al);
					aCount++;
				}
				else {
					actions.removeView(al);
					aCount--;
				}
			}
		});
        
        final ImageButton vButton = (ImageButton) findViewById(R.id.VolumeButton);
        vCount=-1;
        //final LinearLayout gl = new LinearLayout(this);
        vButton.setOnClickListener(new View.OnClickListener() {
        	LinearLayout vl = new LinearLayout(ActionsScreen.this);
			public void onClick(View v) {
				if(vCount==-1) {		
		        	/*LayoutParams params = new LayoutParams(
		        			LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
					params.setMargins(0,0,0,10);
					vl.setLayoutParams(params);*/
					TextView tv = new TextView(ActionsScreen.this);
					tv.setText("Volume");
					tv.setTextSize(20);
					tv.setWidth((int)(displayWidth*.33));
					SeekBar sb = new SeekBar(ActionsScreen.this);
					sb.setFocusable(true);
					sb.setLayoutParams(new LinearLayout.LayoutParams((int)(displayWidth*.60), 
							LinearLayout.LayoutParams.WRAP_CONTENT));
					sb.setMax(7);
					vl.addView(tv);
					vl.addView(sb);
					actions.addView(vl);
					vCount += 2;
				}
				else if (vCount == 0) {
					actions.addView(vl);
					vCount++;
				}
				else {
					actions.removeView(vl);
					vCount--;
				}
			}
		});
        
        final ImageButton bButton = (ImageButton) findViewById(R.id.BrightnessButton);
        bCount=-1;
        //final LinearLayout gl = new LinearLayout(this);
        bButton.setOnClickListener(new View.OnClickListener() {
        	LinearLayout bl = new LinearLayout(ActionsScreen.this);
			public void onClick(View v) {
				if(bCount==-1) {
					TextView tv = new TextView(ActionsScreen.this);
					tv.setText("Brightness");
					tv.setTextSize(20);
					tv.setWidth((int)(displayWidth*.33));
					SeekBar sb = new SeekBar(ActionsScreen.this);
					sb.setFocusable(true);
					sb.setLayoutParams(new LinearLayout.LayoutParams((int)(displayWidth*.60), 
							LinearLayout.LayoutParams.WRAP_CONTENT));
					sb.setMax(255);
					bl.addView(tv);
					bl.addView(sb);
					actions.addView(bl);
					bCount += 2;
				}
				else if (bCount == 0) {
					actions.addView(bl);
					bCount++;
				}
				else {
					actions.removeView(bl);
					bCount--;
				}
			}
		});
        
        final ImageButton awButton = (ImageButton) findViewById(R.id.AwayMessageButton);
        awCount=-1;
        //final LinearLayout gl = new LinearLayout(this);
        awButton.setOnClickListener(new View.OnClickListener() {
        	LinearLayout awl = new LinearLayout(ActionsScreen.this);
			public void onClick(View v) {
				if(awCount==-1) {
					awl.setOrientation(LinearLayout.VERTICAL);
					LinearLayout top = new LinearLayout(ActionsScreen.this);
					LinearLayout bottom = new LinearLayout(ActionsScreen.this);	
					bottom.setGravity(Gravity.CENTER);
					TextView tv = new TextView(ActionsScreen.this);
					tv.setText("Away Message");
					tv.setTextSize(20);
					tv.setWidth((int)(displayWidth*.80));
					CheckBox cb = new CheckBox(ActionsScreen.this);
					top.addView(tv);
					top.addView(cb);
					Button b = new Button(ActionsScreen.this);
					b.setWidth((int)(displayWidth*.8));
					b.setText("Edit Message...");
					bottom.addView(b);
					awl.addView(top);
					awl.addView(bottom);
					actions.addView(awl);
					awCount += 2;
				}
				else if (awCount == 0) {
					actions.addView(awl);
					awCount++;
				}
				else {
					actions.removeView(awl);
					awCount--;
				}
			}
		});
    }
}